#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    // 获取两个输入的时间
    QDateTime timeOld = ui->dateTimeEdit->dateTime();
    QDateTime timeNew = ui->dateTimeEdit_2->dateTime();
    qDebug() << timeOld << timeNew;
    // 计算两个日期之间的秒数差值
    int seconds = timeOld.secsTo(timeNew);
    // 将秒数换算成小时
    int hours = (seconds / 3600) % 24;
    int days = (seconds / 3600) / 24;
    // 将计算结果设置到label中
    ui->label->setText(QString("相差") + QString::number(days) + QString("天") + QString::number(hours) + QString("小时"));
}
